
package com.yanboo.rest;

import me.zhengjie.annotation.Log;
import com.yanboo.domain.CodeColumnConfig;
import com.yanboo.service.CodeColumnConfigService;
import com.yanboo.service.dto.CodeColumnConfigQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import me.zhengjie.utils.PageResult;
import com.yanboo.service.dto.CodeColumnConfigDto;

/**
* @author fdq
* @date 2023-11-23
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "a管理")
@RequestMapping("/api/codeColumnConfig")
public class CodeColumnConfigController {

    private final CodeColumnConfigService codeColumnConfigService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('codeColumnConfig:list')")
    public void exportCodeColumnConfig(HttpServletResponse response, CodeColumnConfigQueryCriteria criteria) throws IOException {
        codeColumnConfigService.download(codeColumnConfigService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询a")
    @ApiOperation("查询a")
    @PreAuthorize("@el.check('codeColumnConfig:list')")
    public ResponseEntity<PageResult<CodeColumnConfigDto>> queryCodeColumnConfig(CodeColumnConfigQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(codeColumnConfigService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增a")
    @ApiOperation("新增a")
    @PreAuthorize("@el.check('codeColumnConfig:add')")
    public ResponseEntity<Object> createCodeColumnConfig(@Validated @RequestBody CodeColumnConfig resources){
        codeColumnConfigService.create(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    /**
     *
     * @param resources
     * @return
     */
    @PutMapping
    @Log("修改a")
    @ApiOperation("修改a")
    @PreAuthorize("@el.check('codeColumnConfig:edit')")
    public ResponseEntity<Object> updateCodeColumnConfig(@Validated @RequestBody CodeColumnConfig resources){
        codeColumnConfigService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除a")
    @ApiOperation("删除a")
    @PreAuthorize("@el.check('codeColumnConfig:del')")
    public ResponseEntity<Object> deleteCodeColumnConfig(@RequestBody unknowType[] ids) {
        codeColumnConfigService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}